var shareMd = {
    template: '#shareMd',
    data() {
        return {
            md:{},
            mdName: '查看分享文章',
            sidebarRight: null,
        }
    },
    
    mounted() {
        this.sidebarRight = $sidebar.fromTemplate('<div id="custom-toc-container">文档添加toc生成目录</div>', {position: 'right'})
        this.getQuery()
    },
    beforeDestroy() {
        $("#custom-toc-container").remove();
    },
    methods: {
        onRefresh(done) {
            setTimeout(done, 1000)
        },
        scrolUp() {
            $(".scroll").scrollTop(0);
        },
        openMenu(){
            this.sidebarRight.toggle()
        },
        addWaterMarker(str) {
            var can = document.createElement('canvas');
            var body = document.getElementById('mdOverBg');
            body.appendChild(can);
            can.width = 350; //画布的宽
            can.height = 300;//画布的高度
            can.style.display = 'none';
            var cans = can.getContext('2d');
            cans.rotate(-20 * Math.PI / 180); //画布里面文字的旋转角度
            cans.font = "20px Microsoft JhengHei"; //画布里面文字的字体
            cans.fillStyle = "rgba(17, 17, 17, 0.50)";//画布里面文字的颜色
            cans.textAlign = 'left'; //画布里面文字的水平位置
            cans.textBaseline = 'Middle'; //画布里面文字的垂直位置
            cans.fillText(str, can.width / 3, can.height / 2); //画布里面文字的间距比例
            body.style.backgroundImage = "url(" + can.toDataURL("image/png") + ")"; //把画布插入到body中
        },
        getQuery() {
            $loading.show('加载中..')
            that = this
            let query = decodeURIComponent(this.$route.query.data)
            if (query != null) {
                getNetMd(getDAes(query),function(result){
                    that.mdName=result.name
                    that.md=result
                    setTimeout(function(){
                        that.WatchMd('overMd', result.data)
                    }, 500)
                })
               
            }

        },
        back() {
			// if(this.$route.matched.length<2){
			// 	  this.$router.replace('/main/home')
			// }else{
				  this.$router.go(-1)
			// }
          
        },
        WatchMd(id, markdown) {
       
            editormd.markdownToHTML(id, {
                htmlDecode: true,
                tocContainer : "#custom-toc-container",
                markdown: markdown,
                emoji: true,
                taskList: true,
                tocm:false,
            });
            this.addWaterMarker('文章由' + this.md.UserId + '编写')
            $loading.hide()
        }
    }
}